<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>vue-入门Day.01 | 让技术更简单</title>

  <!-- keywords -->
  

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="vue.js 入门Day.01vue.js简介vue是一套用于构建用户界面的渐进式框架。与其它大型框架不同的是，Vue 被设计为可以自底向上逐层应用。Vue 的核心库只关注视图层，不仅易于上手，还便于与第三方库或既有项目整合。另一方面，当与现代化的工具链以及各种支持类库结合使用时，Vue 也完全能够为复杂的单页应用提供驱动。 如何快速生成vue脚手架（项目管理）文件1.安装1npm install">
<meta property="og:type" content="article">
<meta property="og:title" content="vue-入门Day.01">
<meta property="og:url" content="http://example.com/2022/03/15/vue-day01/index.html">
<meta property="og:site_name" content="让技术更简单">
<meta property="og:description" content="vue.js 入门Day.01vue.js简介vue是一套用于构建用户界面的渐进式框架。与其它大型框架不同的是，Vue 被设计为可以自底向上逐层应用。Vue 的核心库只关注视图层，不仅易于上手，还便于与第三方库或既有项目整合。另一方面，当与现代化的工具链以及各种支持类库结合使用时，Vue 也完全能够为复杂的单页应用提供驱动。 如何快速生成vue脚手架（项目管理）文件1.安装1npm install">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2022-03-15T08:35:12.000Z">
<meta property="article:modified_time" content="2022-03-15T13:00:12.588Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternative" href="/atom.xml" title="让技术更简单" type="application/atom+xml">
  
  
    <link rel="icon" href="http://7xkj1z.com1.z0.glb.clouddn.com/head.jpg">
  
  
<link rel="stylesheet" href="/css/style.css">

  
  

  
<script src="//cdn.bootcss.com/require.js/2.3.2/require.min.js"></script>

  
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>


  
<meta name="generator" content="Hexo 6.1.0"></head>
<body>
  <div id="container">
    <div id="particles-js"></div>
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			
			<img lazy-src="http://7xkj1z.com1.z0.glb.clouddn.com/head.jpg" class="js-avatar">
			
		</a>

		<hgroup>
		  <h1 class="header-author"><a href="/"></a></h1>
		</hgroup>

		

		
			<div class="switch-btn">
				<div class="icon">
					<div class="icon-ctn">
						<div class="icon-wrap icon-house" data-idx="0">
							<div class="birdhouse"></div>
							<div class="birdhouse_holes"></div>
						</div>
						<div class="icon-wrap icon-ribbon hide" data-idx="1">
							<div class="ribbon"></div>
						</div>
						
						<div class="icon-wrap icon-link hide" data-idx="2">
							<div class="loopback_l"></div>
							<div class="loopback_r"></div>
						</div>
						
						
					</div>
					
				</div>
				<div class="tips-box hide">
					<div class="tips-arrow"></div>
					<ul class="tips-inner">
						<li>菜单</li>
						<li>标签</li>
						
						<li>友情链接</li>
						
						
					</ul>
				</div>
			</div>
		

		<div class="switch-area">
			<div class="switch-wrap">
				<section class="switch-part switch-part1">
					<nav class="header-menu">
						<ul>
						
							<li><a href="/">主页</a></li>
				        
							<li><a href="/archives">所有文章</a></li>
				        
						</ul>
					</nav>
					<nav class="header-nav">
						<div class="social">
							
						</div>
					</nav>
				</section>
				
				
				<section class="switch-part switch-part2">
					<div class="widget tagcloud" id="js-tagcloud">
						
					</div>
				</section>
				
				
				
				<section class="switch-part switch-part3">
					<div id="js-friends">
					
			          <a target="_blank" class="main-nav-link switch-friends-link" href="https://github.com/smackgg/hexo-theme-smackdown">smackdown</a>
			        
			        </div>
				</section>
				

				
			</div>
		</div>
	</header>				
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
  	<div class="overlay">
  		<div class="slider-trigger"></div>
  		<h1 class="header-author js-mobile-header hide"></h1>
  	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
				<img lazy-src="http://7xkj1z.com1.z0.glb.clouddn.com/head.jpg" class="js-avatar">
			</div>
			<hgroup>
			  <h1 class="header-author"></h1>
			</hgroup>
			
			<nav class="header-menu">
				<ul>
				
					<li><a href="/">主页</a></li>
		        
					<li><a href="/archives">所有文章</a></li>
		        
		        <div class="clearfix"></div>
				</ul>
			</nav>
			<nav class="header-nav">
				<div class="social">
					
				</div>
			</nav>
		</header>				
	</div>
</nav>
      <div class="body-wrap"><article id="post-vue-day01" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2022/03/15/vue-day01/" class="article-date">
  	<time datetime="2022-03-15T08:35:12.000Z" itemprop="datePublished">2022-03-15</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      vue-入门Day.01
      
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
        

        
        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="vue-js-入门Day-01"><a href="#vue-js-入门Day-01" class="headerlink" title="vue.js 入门Day.01"></a>vue.js 入门Day.01</h1><h2 id="vue-js简介"><a href="#vue-js简介" class="headerlink" title="vue.js简介"></a>vue.js简介</h2><p>vue是一套用于构建用户界面的<strong>渐进式框架</strong>。与其它大型框架不同的是，Vue 被设计为可以<strong>自底向上逐层应用</strong>。Vue 的核心库只关注视图层，不仅易于上手，还便于与第三方库或既有项目整合。另一方面，当与现代化的工具链以及各种支持类库结合使用时，Vue 也完全能够为复杂的单页应用提供驱动。</p>
<h2 id="如何快速生成vue脚手架（项目管理）文件"><a href="#如何快速生成vue脚手架（项目管理）文件" class="headerlink" title="如何快速生成vue脚手架（项目管理）文件"></a>如何快速生成vue脚手架（项目管理）文件</h2><h3 id="1-安装"><a href="#1-安装" class="headerlink" title="1.安装"></a>1.安装</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -g @vue/cli <span class="comment">//安装vue cli插件,主要使用vue2x版本</span></span><br></pre></td></tr></table></figure>
<h3 id="2-创建文件"><a href="#2-创建文件" class="headerlink" title="2.创建文件"></a>2.创建文件</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vue create 文件名</span><br></pre></td></tr></table></figure>
<h3 id="3-启动文件，启动服务器，代码运行"><a href="#3-启动文件，启动服务器，代码运行" class="headerlink" title="3.启动文件，启动服务器，代码运行"></a>3.启动文件，启动服务器，代码运行</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm run serve; <span class="comment">//启动服务器，让代码运行</span></span><br><span class="line">code ./; <span class="comment">//打开vs code开始编写代码</span></span><br></pre></td></tr></table></figure>
<h2 id="包的引用"><a href="#包的引用" class="headerlink" title="包的引用"></a>包的引用</h2><p>在vue中也同样使用着大量的包，node.js中主要使用commenJS，而在vue.JS中主要使用ES6 Moudle,下面我们来看一下这两者的使用区别：</p>
<h3 id="ES6-Module-模块引入规范："><a href="#ES6-Module-模块引入规范：" class="headerlink" title="ES6 Module 模块引入规范："></a>ES6 Module 模块引入规范：</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">import 变量名 from <span class="string">&quot;地址&quot;</span>; <span class="comment">//引入</span></span><br><span class="line"></span><br><span class="line">export ...（表达式）; <span class="comment">//导出</span></span><br></pre></td></tr></table></figure>

<h3 id="CommonJS-模块引入规范（Node中使用的规范）"><a href="#CommonJS-模块引入规范（Node中使用的规范）" class="headerlink" title="CommonJS 模块引入规范（Node中使用的规范）:"></a>CommonJS 模块引入规范（Node中使用的规范）:</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">const xxx = require(xxx);<span class="comment">//引入</span></span><br><span class="line">module.exports = xxx; <span class="comment">//导出</span></span><br></pre></td></tr></table></figure>

<h2 id="vue文件与普通的js文件有啥区别"><a href="#vue文件与普通的js文件有啥区别" class="headerlink" title="vue文件与普通的js文件有啥区别"></a>vue文件与普通的js文件有啥区别</h2><h3 id="vue文件存在着三大标签：-lt-template-gt-lt-script-gt-lt-style-gt"><a href="#vue文件存在着三大标签：-lt-template-gt-lt-script-gt-lt-style-gt" class="headerlink" title="vue文件存在着三大标签：&lt;template&gt;&lt;script&gt;&lt;style&gt;"></a>vue文件存在着三大标签：<code>&lt;template&gt;&lt;script&gt;&lt;style&gt;</code></h3><p>可以写html、css、js，而一般的js文件只能写js代码</p>
<h2 id="声明式渲染"><a href="#声明式渲染" class="headerlink" title="声明式渲染"></a>声明式渲染</h2><h3 id="Vue-js-的核心是一个允许采用简洁的模板语法来声明式地将数据渲染进-DOM-的系统："><a href="#Vue-js-的核心是一个允许采用简洁的模板语法来声明式地将数据渲染进-DOM-的系统：" class="headerlink" title="Vue.js 的核心是一个允许采用简洁的模板语法来声明式地将数据渲染进 DOM 的系统："></a>Vue.js 的核心是一个允许采用简洁的模板语法来声明式地将数据渲染进 DOM 的系统：</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- &#123;&#123;data中的属性&#125;&#125;表示插值 --&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">h2</span>&gt;</span>&#123;&#123;str2&#125;&#125;<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br></pre></td></tr></table></figure>
 <figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">// 引入其他模块</span></span><br><span class="line">import str from <span class="string">&quot;./test.js&quot;</span>;</span><br><span class="line">import VueList from <span class="string">&quot;./vue-list.vue&quot;</span>;<span class="comment">//引入vue-list.vue模块，把这个模块作为标签插入到标签中</span></span><br><span class="line">export default <span class="punctuation">&#123;</span></span><br><span class="line">    components<span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="comment">//components是一个方法</span></span><br><span class="line">        VueList<span class="punctuation">,</span></span><br><span class="line">    <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">    data()<span class="punctuation">&#123;</span></span><br><span class="line">        <span class="comment">// 必须要有返回值</span></span><br><span class="line">        return<span class="punctuation">&#123;</span></span><br><span class="line">        str2<span class="punctuation">:</span>&#x27;我是一个新的title&#x27;<span class="punctuation">,</span></span><br><span class="line">        num<span class="punctuation">:</span><span class="number">10</span><span class="punctuation">,</span></span><br><span class="line">        isShow<span class="punctuation">:</span><span class="keyword">true</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>

<p> 现在数据和 DOM 已经被建立了关联，所有东西都是响应式的。一个 Vue 应用会将其挂载到一个 DOM 元素上 (对于这个例子是 #app) 然后对其进行完全控制。<br> 例：<br> <figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//  在main.js中进行修改</span></span><br><span class="line"></span><br><span class="line"> import Vue from &#x27;vue&#x27;</span><br><span class="line"><span class="comment">// import App from &#x27;./App.vue&#x27;</span></span><br><span class="line">import vueBase from <span class="string">&quot;./vue-base.vue&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//调试信息的配置</span></span><br><span class="line">Vue.config.productionTip = <span class="keyword">false</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 虚拟dom</span></span><br><span class="line">new Vue(<span class="punctuation">&#123;</span></span><br><span class="line">  render<span class="punctuation">:</span> h =&gt; h(vueBase)<span class="punctuation">,</span></span><br><span class="line"><span class="punctuation">&#125;</span>).$mount(&#x27;#app&#x27;)<span class="comment">//挂载</span></span><br></pre></td></tr></table></figure></p>
<p> 除了文本插值，我们还可以像这样来绑定元素 attribute：<br> <figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span>=<span class="string">&quot;contentStr&quot;</span> <span class="attr">v-bind:title</span>=<span class="string">&quot;str2&quot;</span>&gt;</span>调整h2的内容<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">     <span class="comment">&lt;!-- v-bind 绑定后面接的为data中的数据 --&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;box&quot;</span> <span class="attr">v-show</span>=<span class="string">&quot;isShow&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">     <span class="comment">&lt;!-- 通过控制css的形式来使条件生效 ，功耗小--&gt;</span></span><br><span class="line">     <span class="comment">&lt;!-- &lt;div class=&quot;box&quot; v-if=&quot;isShow&quot;&gt;&lt;/div&gt; --&gt;</span></span><br><span class="line">     <span class="comment">&lt;!-- 通过删除节点、插入节点的形式来时条件生效，功耗大 ,两者除了功耗不同，其他的都大同小异--&gt;</span></span><br></pre></td></tr></table></figure><br>      <figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">      <span class="comment">// 引入其他模块</span></span><br><span class="line">    import str from <span class="string">&quot;./test.js&quot;</span>;</span><br><span class="line">    import VueList from <span class="string">&quot;./vue-list.vue&quot;</span>;<span class="comment">//引入vue-list.vue模块，把这个模块作为标签插入到标签中</span></span><br><span class="line">    export default <span class="punctuation">&#123;</span> </span><br><span class="line">    components<span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="comment">//components是一个方法</span></span><br><span class="line">        VueList<span class="punctuation">,</span></span><br><span class="line">    <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">    data()<span class="punctuation">&#123;</span></span><br><span class="line">        <span class="comment">// 必须要有返回值</span></span><br><span class="line">        return<span class="punctuation">&#123;</span></span><br><span class="line">        str2<span class="punctuation">:</span>&#x27;我是一个新的title&#x27;<span class="punctuation">,</span></span><br><span class="line">        num<span class="punctuation">:</span><span class="number">10</span><span class="punctuation">,</span></span><br><span class="line">        isShow<span class="punctuation">:</span><span class="keyword">true</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">    methods<span class="punctuation">:</span><span class="punctuation">&#123;</span><span class="comment">//事件处理函数的方法</span></span><br><span class="line">        contentStr<span class="punctuation">:</span>function()<span class="punctuation">&#123;</span></span><br><span class="line">            <span class="comment">// console.log(&#x27;hhhhhh&#x27;);</span></span><br><span class="line">            this.isShow=!this.isShow</span><br><span class="line">            <span class="comment">// this.box=&quot;xxxx&quot;</span></span><br><span class="line">        <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span>;</span><br></pre></td></tr></table></figure><br>这里我们遇到了一点新东西。你看到的 <strong>v-bind：</strong>被称为指令。指令带有前缀v-，以表示它们是 Vue 提供的特殊 <strong>attribute</strong>。可能你已经猜到了，它们会在渲染的 DOM 上应用特殊的响应式行为。@后接的事件行为，是一个方法，具体表现在methods中。</p>
<h2 id="条件与循环"><a href="#条件与循环" class="headerlink" title="条件与循环"></a>条件与循环</h2><h3 id="v-if则表示条件，v-for则表示循环"><a href="#v-if则表示条件，v-for则表示循环" class="headerlink" title="v-if则表示条件，v-for则表示循环"></a><code>v-if</code>则表示条件，<code>v-for</code>则表示循环</h3><h4 id="v-if条件"><a href="#v-if条件" class="headerlink" title="v-if条件"></a><code>v-if</code>条件</h4><p>例子如下：<br> <figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span>=<span class="string">&quot;contentStr&quot;</span> <span class="attr">v-bind:title</span>=<span class="string">&quot;str2&quot;</span>&gt;</span>调整h2的内容<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">     <span class="comment">&lt;!-- v-bind 绑定后面接的为data中的数据 --&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;box&quot;</span> <span class="attr">v-if</span>=<span class="string">&quot;isShow&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure><br>      <figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">    data()<span class="punctuation">&#123;</span></span><br><span class="line">        <span class="comment">// 必须要有返回值</span></span><br><span class="line">        return<span class="punctuation">&#123;</span></span><br><span class="line">        str2<span class="punctuation">:</span>&#x27;我是一个新的title&#x27;<span class="punctuation">,</span></span><br><span class="line">        num<span class="punctuation">:</span><span class="number">10</span><span class="punctuation">,</span></span><br><span class="line">        isShow<span class="punctuation">:</span><span class="keyword">true</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">    methods<span class="punctuation">:</span><span class="punctuation">&#123;</span><span class="comment">//事件处理函数的方法</span></span><br><span class="line">        contentStr<span class="punctuation">:</span>function()<span class="punctuation">&#123;</span></span><br><span class="line">            <span class="comment">// console.log(&#x27;hhhhhh&#x27;);</span></span><br><span class="line">            this.isShow=!this.isShow</span><br><span class="line">            <span class="comment">// this.box=&quot;xxxx&quot;</span></span><br><span class="line">        <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span>;</span><br></pre></td></tr></table></figure><br>这个例子演示了我们不仅可以把数据绑定到 DOM 文本或 attribute，还可以绑定到 DOM 结构。此外，Vue 也提供一个强大的过渡效果系统，可以在 Vue 插入&#x2F;更新&#x2F;移除元素时自动应用过渡效果。</p>
<p>此外，还有其它很多指令，每个都有特殊的功能。例如，v-for 指令可以绑定数组的数据来渲染一个项目列表：</p>
<h4 id="v-for循环"><a href="#v-for循环" class="headerlink" title="v-for循环"></a><code>v-for</code>循环</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">li</span> <span class="attr">v-for</span>=<span class="string">&quot;item in list&quot;</span> <span class="attr">:key</span>=<span class="string">&quot;item&quot;</span>&gt;</span>&#123;&#123;item.name&#125;&#125;<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br></pre></td></tr></table></figure>
  <figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">  export default <span class="punctuation">&#123;</span></span><br><span class="line">    data()<span class="punctuation">&#123;</span></span><br><span class="line">        return<span class="punctuation">&#123;</span></span><br><span class="line">        list<span class="punctuation">:</span><span class="punctuation">[</span></span><br><span class="line">            <span class="punctuation">&#123;</span></span><br><span class="line">                name<span class="punctuation">:</span>&#x27;glr&#x27;<span class="punctuation">,</span></span><br><span class="line">                age<span class="punctuation">:</span><span class="number">21</span></span><br><span class="line">            <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="punctuation">&#123;</span></span><br><span class="line">                name<span class="punctuation">:</span>&#x27;zy&#x27;<span class="punctuation">,</span></span><br><span class="line">                age<span class="punctuation">:</span><span class="number">21</span></span><br><span class="line">            <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="punctuation">&#123;</span></span><br><span class="line">                name<span class="punctuation">:</span>&#x27;yxf&#x27;<span class="punctuation">,</span></span><br><span class="line">                age<span class="punctuation">:</span><span class="number">21</span></span><br><span class="line">            <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="punctuation">&#123;</span></span><br><span class="line">                name<span class="punctuation">:</span>&#x27;lk&#x27;<span class="punctuation">,</span></span><br><span class="line">                age<span class="punctuation">:</span><span class="number">21</span></span><br><span class="line">            <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="punctuation">&#123;</span></span><br><span class="line">                name<span class="punctuation">:</span>&#x27;zxy&#x27;<span class="punctuation">,</span></span><br><span class="line">                age<span class="punctuation">:</span><span class="number">21</span></span><br><span class="line">            <span class="punctuation">&#125;</span></span><br><span class="line">        <span class="punctuation">]</span></span><br><span class="line">        <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<p>建议尽可能在使用 <code>v-for</code> 时提供<code> :key attribute</code>，如上代码所示，除非遍历输出的 DOM 内容非常简单，或者是刻意依赖默认行为以获取性能上的提升。</p>
<p>因为它是 Vue 识别节点的一个通用机制，<strong>key</strong> 并不仅与 <code>v-for</code> 特别关联。后面我们将在指南中看到，它还具有其它用途。</p>

      
    </div>
    
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2022/03/16/vue-day.02/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">&lt;</strong>
      <div class="article-nav-title">
        
          vue-入门Day.02
        
      </div>
    </a>
  
  
    <a href="/2022/03/14/%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86/" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">项目管理</div>
      <strong class="article-nav-caption">&gt;</strong>
    </a>
  
</nav>

  
</article>


<div class="ds-share share" data-thread-key="vue-day01" data-title="vue-入门Day.01" data-url="http://example.com/2022/03/15/vue-day01/"  data-images="http://7xkj1z.com1.z0.glb.clouddn.com/head.jpg" data-content="vue-入门Day.01">
    <div class="ds-share-inline">
      <ul  class="ds-share-icons-16">
      	<li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
        <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
        <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
        <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
        <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>
      </ul>
      <div class="ds-share-icons-more">
      </div>
    </div>
 </div>
 





</div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
      <div class="footer-left">
        &copy; 2022 John Doe
      </div>
        <div class="footer-right">
          <a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/smackgg/hexo-theme-smackdown" target="_blank">Smackdown</a>
        </div>
    </div>
  </div>
</footer>
    </div>
    
  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">



<script>
	var yiliaConfig = {
		fancybox: true,
		mathjax: true,
		animate: true,
		isHome: false,
		isPost: true,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false
	}
</script>

<script src="/js/main.js"></script>




<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';                 
    }       
});
</script>

<script src="//cdn.bootcss.com/mathjax/2.7.0/MathJax.js"></script>


  </div>
</body>
</html>